#include "mywidget.h"
#include "ui_mywidget.h"
#include <QPainter>

MyWidget::MyWidget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::MyWidget)
{
    ui->setupUi(this);
}

MyWidget::~MyWidget()
{
    delete ui;
}

// 绘图事件实现
void MyWidget::paintEvent(QPaintEvent *event)
{
//    // 实例化 painter 对象
//    QPainter painter(this);

//    // 设置颜色
//    QPen pen(QColor(255, 0, 0));
//    pen.setWidth(3);
//    pen.setStyle(Qt::DotLine);
//    painter.setPen(pen);

//    // 设置填充色 画刷
//    QBrush brush(Qt::cyan);
//    brush.setStyle(Qt::Dense1Pattern);
//    painter.setBrush(brush);


//    painter.drawLine(QPoint(0, 0), QPoint(100, 100));

//    painter.drawEllipse(QPoint(300, 200), 200, 100);

//    painter.drawRect(20, 20, 50, 50);

//    painter.drawText(QRect(10, 300, 150, 50), "我爱我的祖国");


    /*********************************************************************************************/

    QPainter painter(this);
//    painter.drawEllipse(QPoint(100, 60), 50, 50);
//    // 设置抗锯齿能力
//    painter.setRenderHint(QPainter::Antialiasing);
//    painter.drawEllipse(QPoint(200, 60), 50, 50);


    painter.drawRect(20, 20, 50, 50);
    // 移动画家
    painter.translate(100, 0);
    // 保存画家状态
    painter.save();

    painter.drawRect(20, 20, 50, 50);

    painter.translate(100, 0);

    // 还原上一次保存的状态
    painter.restore();
    painter.drawRect(20, 20, 50, 50);


}

